<?php
namespace app\admin\model\role;
use think\Model;
use think\facade\Db;
use app\admin\common;
class AdminRole extends Model {
	private $table_obj;
	
	public function selectRole($where,$field='*'){
		extract(common::get('admin_role',[$where,$field,__function__]));
		if(empty($data)){
			$admin=new AdminRole;
			$data=$admin::where($where)->field($field)->find()->toArray();
			common::set($data);
		}
		return $data;
	}
	/**
	 * 插入数据
	 * 
	 */
	public function insertAdminData($data){
		common::delete("admin_role");
		$admin=new AdminRole;
		$admin->save($data);
		return $admin->id;
	}
	/**
	 * 更新数据
	 */
	public function updateAdminData($up,$where){
		common::delete("admin_role");
		$admin=AdminRole::find($where);
		$r=$admin->save($up);
		return $r;
	}
	
	public function selectRoleDataCount($where){
		extract(common::get('admin_role',[$where,__function__]));
		if(empty($data)){
			$data=AdminRole::where($where)->field("count(id) num")->find();
			common::set($data);
		}
		return $data;
	}
	
	public function selectRolePage($where,$limit,$param){
		extract(common::get('admin_role',[$where,$limit,$param,__function__]));
		if(empty($data)){
			$data =Db::name('admin_role')->where($where)->paginate([
				"list_rows"=>next($limit),
				'query'=>$param
			]);
			common::set($data);
		}
		return $data->render();
		
	}
	public function selectRolePageData($where,$order,$limit){
		extract(common::get('admin_role',[$where,$order,$limit,__function__]));
		if(empty($data)){
			$data=Db::name('admin_role')->where($where)->order($order)->paginate(end($limit),reset($limit));
			if($data){
				common::set($data->toArray());
				return $data->toArray();
			}
		}
		return $data;
	}
	public function selectRoleData($where,$order,$limit){
		extract(common::get('admin_role',[$where,$order,$limit,__function__]));
		if(empty($data)){
			$data=AdminRole::where($where)->limit(current($limit),next($limit))->order($order)->select();
			common::set($data->toArray());
			return $data->toArray();
		}
		return $data;
	}
	
	public function findRolePageData($where,$field="*"){
		extract(common::get('admin_role',[$where,$field,__function__]));
		if(empty($data)){
			$data=Db::name("admin_role")->where($where)->field($field)->find();
			common::set($data);
		}
		return $data;
	}
}
?>